package com.back.demo.service;

import com.back.demo.controller.myVO.judgeVO.SingleItemResVO;
import com.back.demo.controller.myVO.judgeVO.AllStudentsSingleGradeResVO;
import com.back.demo.controller.myVO.judgeVO.SingleStudentAllGradesResVO;
import com.back.demo.controller.myVO.studentVO.StudentPositionVO;
import com.back.demo.controller.myVO.studentVO.StudentPracticeVO;
import com.back.demo.controller.myVO.studentVO.StudentResearchVO;
import com.back.demo.mapper.JudgeMapper;
import com.back.demo.mapper.myDO.judgeDO.SingleStudentAllGradesDO;
import com.back.demo.mapper.myDO.studentDO.StudentPositionDO;
import com.back.demo.mapper.myDO.studentDO.StudentPracticeDO;
import com.back.demo.mapper.myDO.studentDO.StudentResearchDO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@org.springframework.stereotype.Service
public class JudgeService {
    @Autowired
    private JudgeMapper judgeMapper;

    @Autowired
    private StudentService studentService;

    // 得到所有学生的某项成绩
    public ArrayList<AllStudentsSingleGradeResVO> acquireAllStudentsSingleGrade(Integer type) {
        ArrayList<SingleStudentAllGradesDO> listDO = judgeMapper.selectAllStudentsSingleGrade();
        ArrayList<AllStudentsSingleGradeResVO> listVO = new ArrayList<>();
        switch (type) {
            case 1:
                for (SingleStudentAllGradesDO stuDO : listDO) {
                    AllStudentsSingleGradeResVO stuVO = new AllStudentsSingleGradeResVO();
                    stuVO.setStudentId(stuDO.getStudentId());
                    stuVO.setStudentName(stuDO.getStudentName());
                    stuVO.setGrade(stuDO.getSummaryScore());
                    listVO.add(stuVO);
                }
                return listVO;
            case 2:
                for (SingleStudentAllGradesDO stuDO : listDO) {
                    AllStudentsSingleGradeResVO stuVO = new AllStudentsSingleGradeResVO();
                    stuVO.setStudentId(stuDO.getStudentId());
                    stuVO.setStudentName(stuDO.getStudentName());
                    stuVO.setGrade(stuDO.getResearchScore());
                    listVO.add(stuVO);
                }
                return listVO;
            case 3:
                for (SingleStudentAllGradesDO stuDO : listDO) {
                    AllStudentsSingleGradeResVO stuVO = new AllStudentsSingleGradeResVO();
                    stuVO.setStudentId(stuDO.getStudentId());
                    stuVO.setStudentName(stuDO.getStudentName());
                    stuVO.setGrade(stuDO.getPositionScore());
                    listVO.add(stuVO);
                }
                return listVO;
            case 4:
                for (SingleStudentAllGradesDO stuDO : listDO) {
                    AllStudentsSingleGradeResVO stuVO = new AllStudentsSingleGradeResVO();
                    stuVO.setStudentId(stuDO.getStudentId());
                    stuVO.setStudentName(stuDO.getStudentName());
                    stuVO.setGrade(stuDO.getPracticeScore());
                    listVO.add(stuVO);
                }
                return listVO;
            default:
                System.out.println("查询失败（Judge）");
                return null;


        }
//        return judgeMapper.selectAllStudentsGrade();
    }

    // 得到单个学生的所有成绩
    public SingleStudentAllGradesResVO acquireSingleStudentAllGrades(String studentId) {
        SingleStudentAllGradesDO resDO = judgeMapper.selectSingleStudentAllGrades(studentId);
        SingleStudentAllGradesResVO resVO = new SingleStudentAllGradesResVO();
        resVO.setSummaryScore(resDO.getSummaryScore());
        resVO.setResearchScore(resDO.getResearchScore());
        resVO.setPositionScore(resDO.getPositionScore());
        resVO.setPracticeScore(resDO.getPracticeScore());
        resVO.setGpa(resDO.getGpa());
        resVO.setSumScore(resDO.getSumScore());
        return resVO;
    }

    // 得到单个学生的个人总结
    public SingleItemResVO<String> acquireSingleStudentSummary(String studentId, String studentName, Integer userId) {
        SingleItemResVO<String> resVO = new SingleItemResVO<>();
        resVO.setStudentId(studentId);
        resVO.setStudentName(studentName);
        ArrayList<String> listVO = new ArrayList<>();
        String summary = judgeMapper.selectSingleStudentSummaryByUserId(userId);
        listVO.add(summary); // 此数组只有一个元素
        resVO.setItemList(listVO);
        return resVO;
    }

    // 得到单个学生的科研信息
    public SingleItemResVO<StudentResearchVO> acquireSingleStudentResearch(String studentId, String studentName, Integer userId) {
        List<StudentResearchDO> listDO = judgeMapper.selectSingleStudentResearchByUserId(userId);
        SingleItemResVO<StudentResearchVO> resVO = new SingleItemResVO<>();
        resVO.setStudentId(studentId);
        resVO.setStudentName(studentName);
        ArrayList<StudentResearchVO> listVO = new ArrayList<>();
        for (StudentResearchDO researchDO : listDO) {
            StudentResearchVO researchVO = new StudentResearchVO();
            researchVO.setResearchType(researchDO.getResearchType());
            researchVO.setResearchTime(researchDO.getResearchTime());
            researchVO.setResearchName(researchDO.getResearchName());
            researchVO.setResearchContent(researchDO.getResearchContent());
            listVO.add(researchVO);
        }
        resVO.setItemList(listVO);
        return resVO;
    }

    // 得到单个学生的学生骨干服务信息
    public SingleItemResVO<StudentPositionVO> acquireSingleStudentPosition(String studentId, String studentName, Integer userId) {
        List<StudentPositionDO> listDO = judgeMapper.selectSingleStudentPositionByUserId(userId);
        SingleItemResVO<StudentPositionVO> resVO = new SingleItemResVO<>();
        resVO.setStudentId(studentId);
        resVO.setStudentName(studentName);
        ArrayList<StudentPositionVO> listVO = new ArrayList<>();
        for (StudentPositionDO positionDO : listDO) {
            StudentPositionVO positionVO = new StudentPositionVO();
            positionVO.setPositionName(positionDO.getPositionName());
            positionVO.setPositionStartDate(positionDO.getPositionStartDate());
            positionVO.setPositionEndDate(positionDO.getPositionEndDate());
            positionVO.setPositionReport(positionDO.getPositionReport());
            listVO.add(positionVO);
        }
        resVO.setItemList(listVO);
        return resVO;
    }

    // 得到单个学生的社会实践活动信息
    public SingleItemResVO<StudentPracticeVO> acquireSingleStudentPractice(String studentId, String studentName, Integer userId) {
        List<StudentPracticeDO> listDO = judgeMapper.selectSingleStudentPracticeByUserId(userId);
        SingleItemResVO<StudentPracticeVO> resVO = new SingleItemResVO<>();
        resVO.setStudentId(studentId);
        resVO.setStudentName(studentName);
        ArrayList<StudentPracticeVO> listVO = new ArrayList<>();
        for (StudentPracticeDO practiceDO : listDO) {
            StudentPracticeVO practiceVO = new StudentPracticeVO();
            practiceVO.setPracticeDate(practiceDO.getPracticeDate());
            practiceVO.setPracticeName(practiceDO.getPracticeName());
            practiceVO.setPracticeSponsor(practiceDO.getPracticeSponsor());
            practiceVO.setPracticeTheme(practiceDO.getPracticeTheme());
            practiceVO.setPracticeWork(practiceDO.getPracticeWork());
            practiceVO.setPracticeLength(practiceDO.getPracticeLength());
            listVO.add(practiceVO);
        }
        resVO.setItemList(listVO);
        return resVO;
    }

    public void rate(String studentId, int type, double grade) {

        //System.out.println(mainId);
        switch (type) {
            case 1:
                judgeMapper.rateSummary(studentId, grade);
                break;
            case 2:
                judgeMapper.rateResearch(studentId, grade);
                break;
            case 3:
                judgeMapper.ratePosition(studentId, grade);
                break;
            case 4:
                judgeMapper.ratePractice(studentId, grade);
                break;
        }
    }
}
